package com.buercorp.wangyu.core1.ch12.threads;

public class ThreadPriorityTest {

    //线程优先级的测试 范围1~10

        public static void main(String[] args) {
            //主线程默认的优先级
            System.out.println(Thread.currentThread().getName()+"-->"+Thread.currentThread().getPriority());

            MyPriority myPriority = new MyPriority();

            Thread t1 = new Thread(myPriority,"11");
            Thread t2 = new Thread(myPriority,"22");
            Thread t3 = new Thread(myPriority,"33");
            Thread t4 = new Thread(myPriority,"44");
            Thread t5 = new Thread(myPriority,"55");

            //先设置优先级再启动
            // 默认 5
            t1.start();

            t2.setPriority(4);
            t2.start();

            t3.setPriority(Thread.MAX_PRIORITY);
            t3.start();

            t4.setPriority(Thread.MIN_PRIORITY);
            t4.start();

            //直接报错 范围1~10
            t5.setPriority(11);
            t5.start();


        }

    }

    class MyPriority implements Runnable{

        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName()+"-->"+Thread.currentThread().getPriority());
        }
    }

